#include "app_buffer.h"
buffer_t *buffer;

void *test_read(void *);
void *test_write(void *);
int main(void)
{
    // 初始化缓冲区
    buffer = App_Buffer_Init(10);
    App_Buffer_Write(buffer, "hello", 5);
    char data[10];
    int real_len = App_Buffer_Read(buffer, data, 5);
    log_info("%d",real_len);
    log_info("read: %.*s", real_len, data);

    pthread_t t1;
    pthread_t t2;
    pthread_create(&t1, NULL, test_read, NULL);
    pthread_create(&t2, NULL, test_write, NULL);

    pthread_join(t1, NULL);
    pthread_join(t2, NULL);
}

void *test_read(void *)
{
    char data[10] = {0};
    while (1)
    {
        int len = App_Buffer_Read(buffer, data, 10);
        
        if (len > 0)
        {
            log_info("收到数据：%.*s", len, data);
        }
    }
}
void *test_write(void *)
{
    while (1)
    {
        App_Buffer_Write(buffer, "asdsffs", 7);
        sleep(3);
    }
}